<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.org/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body>
<script src="/resources/layui/layui.js"></script>
<script th:inline="none">
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','table'], function(){
        var layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,$=layui.jquery;

        //部门下拉菜单

            $.ajax({
                type:'get',
                url:'/dept/depts',
                success:function (res) {
                    var depts=res.data.depts;
                    if(depts.length>0){
                        for(var i=0;i<depts.length;i++){
                            var sel='';
                            var dept=depts[i];
                            if(depts[i].id==$("#dept").val()){
                                sel='selected';
                            }
                            $("#deptid").append("<option  value='"+dept.id+"' "+sel+">"+dept.name+"</option>")
                        }
                    }
                    //渲染下拉菜单
                    layui.form.render("select")
                }
            })
        //职位的下拉菜单
        $.ajax({
            type:'get',
            url:'/dictionary/selectEmpByType',
            success:function (res) {
                var emps=res.data.dictionaries;
                if(emps.length>0){
                    for(var i=0;i<emps.length;i++){
                        var sel='';
                        var emp=emps[i];
                        if(emps[i].id==$("#empId").val()){
                            sel='selected';
                        }
                        $("#position").append("<option value='"+emp.id+"' "+sel+" >"+emp.name+"</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select")
            }
        })
        //选中性别
        $('[name=sex]').each(function (i, item) {
            if ($(item).val() == $("#sexid").val()) {
                //更改选中值
                $(item).prop('checked', true);
                //重新渲染
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        });
        //选中状态
        $('[name=statues]').each(function (i,item) {
            if($(item).val()==$("#statuesid").val()){
                //更改选中值
                $(item).prop('checked', true);
                //重新渲染
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        })
        //开启状态
        $('[name=available]').each(function (i,item) {
            if($(item).val()==$("#availid").val()){
                //更改选中值
                $(item).prop('checked', true);
                //重新渲染
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        })
        //修改的ajax请求
        $("#btn_update").click(function () {
            $.ajax({
                type:'post',
                url:'/user/updUser',
                data:$("#updateForm").serialize(),
                success:function () {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭当前页
                    //刷新父类页面
                    window.parent.location.reload()
                }
            })
        })
    })
</script>
    <input type="hidden" id="sexid">
    <input type="hidden" id="dept">
    <input type="hidden" id="empId">
    <input type="hidden" id="statuesid">
    <input type="hidden" id="availid">
<form class="layui-form" action="" id="updateForm">
    <input type="hidden" id="uid" name="uid">
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" id="telephone" name="telephone" required  lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">生日</label>
        <div class="layui-input-inline">
            <input type="Date" id="birthday" name="birthday" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <select id="deptid" name="dept" lay-verify="required">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <select id="position" name="positionid" lay-verify="required">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入职时间</label>
        <div class="layui-input-inline">
            <input type="Date" id="entry" name="entry" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="statues" value="1"  title="在职">
            <input type="radio" name="statues" value="0" title="休假">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            <input type="radio" name="available" value="1" title="启用" >
            <input type="radio" name="available" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <!--<button class="layui-btn" lay-submit lay-filter="formDemo" id="btn_add">立即提交</button>-->
            <input type="button" class="layui-btn" id="btn_update" value="立即提交" >
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>